<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <textarea id="textarea">衣服 鞋子 裤子 衣服 裤子</textarea>
        <button>去重</button>
        <textarea id="textarea-after"></textarea>
        <script>
            let btn = document.querySelector("button");
            let textarea = document.getElementById("textarea");
            let textareaAfter = document.getElementById("textarea-after");
            let arr = [];
            btn.onclick = () => {
                console.log(typeof textarea.value);
                let textareaValue = textarea.value;
                let arr2 = textareaValue.split(" ");
                console.log(arr2);
                for (let i = 0; i < arr2.length; i++){
                    if(arr.indexOf(arr2[i]) === -1){
                        arr.push(arr2[i]);
                        console.log(arr)
                }
            };
            textareaAfter.value = arr.join(" ");
        }
        </script>
    </body>
</html>
